package com.it.service.impl;

import com.it.common.Result;
import com.it.dao.UserMapper;
import com.it.domain.User;
import com.it.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Override
    public Object AddUser(User user) {

        User user1 = userMapper.SelectUser(user.getUsername().trim(), user.getPassword().trim());
        if(user1 != null){
            return Result.fail("303","用户存在");
        }
        else{
            if(userMapper.AddUser(user)>0){
                return Result.success("200","用户添加成功");
            }
            else{
                return Result.fail("405","用户添加失败");
            }
        }
    }

    @Override
    public boolean DeleteUser(Integer id) {
        return userMapper.DeleteUser(id)>0;
    }

    @Override
    public boolean UpdateUser(User user) {
        return userMapper.UpdateUser(user)>0;
    }

    @Override
    public User SelectById(Integer id) {
        return userMapper.SelectById(id);
    }

    @Override
    public List<User> SelectAll(Integer PageNum, Integer PageSize, String username) {
        return userMapper.SelectAll(PageNum,PageSize,username);
    }

    @Override
    public Integer SelectTotal() {
        return userMapper.SelectTotal();
    }

    @Override
    public User login(String username, String password) {

        return userMapper.SelectUser(username,password);
    }

    @Override
    public List<User> SelectRatio() {

        return userMapper.SelectRatio();
    }

    @Override
    public List<User> SelectAddress() {
        return userMapper.SelectAddress();
    }
}
